// state对象直接赋值会改变引用(失去响应式)
export const deepStateCopy = (state, data) => {
	for (const key in data) {
		state[key] = data[key];
	}
};
// state对象属性
export const deleteStateKeys = state => {
	for (const key in state) {
		delete state[key];
	}
};

// 自动注入modules
export const AutoInjectModule = (
	files,
	ignore: Array<string> = [],
	suffix: '.ts' | '.js' = '.ts'
) => {
	const modules = {};
	files.keys().forEach((key: string) => {
		if (!ignore.some(item => key.includes(item))) {
			const childModule = files(key).default;
			const moduleKey = key.slice(key.lastIndexOf('/') + 1).replace(suffix, '');
			modules[moduleKey] = childModule;
		}
	});
	return modules;
};

// 快捷选择
export const shortcuts = [
	{
		text: '一周内',
		value: () => {
			const end = new Date();
			const start = new Date();
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
			return [start, end];
		},
	},
	{
		text: '一个月内',
		value: () => {
			const end = new Date();
			const start = new Date();
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
			return [start, end];
		},
	},
	{
		text: '三个月内',
		value: () => {
			const end = new Date();
			const start = new Date();
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
			return [start, end];
		},
	},
	{
		text: '一年内',
		value: () => {
			const end = new Date();
			const start = new Date();
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
			return [start, end];
		},
	},
];
// 直接范围一年内，不能过过当前时间
export const disabledDate = (time: Date) => {
	const curDate = new Date().getTime();
	const three = 365 * 24 * 3600 * 1000;
	const threeMonths = curDate - three;
	return time.getTime() > Date.now() || time.getTime() < threeMonths;
};
